package com.hrm.controller.popup;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.hrm.model.dto.code.CodeDTO;
import com.hrm.model.dto.code.ZipcodeDTO;
import com.hrm.model.service.ZipcodeService;

public class PopZipcodeListController extends AbstractFormController{
	private ZipcodeService zipcodeService;
	
	public void setZipcodeService(ZipcodeService zipcodeService) {
		this.zipcodeService = zipcodeService;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest request,
			HttpServletResponse response, Object arg2, BindException arg3)
			throws Exception {
		
		ModelAndView mv = new ModelAndView();
//		System.out.println("Submission---------------");
		String zipcodeId = request.getParameter("zipcodeId");
		String addressId = request.getParameter("addressId");
		mv.addObject("zipcodeId", zipcodeId);
		mv.addObject("addressId", addressId);

		List list = zipcodeService.getAllZipcode((ZipcodeDTO)arg2);
		mv.addObject("list", list);
		
		mv.setViewName("popZipcodeList");
		
		return mv;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse response, BindException arg2) throws Exception {
		
		ModelAndView mv = new ModelAndView();
		
		String zipcodeId = request.getParameter("zipcodeId");
		String addressId = request.getParameter("addressId");
		mv.addObject("zipcodeId", zipcodeId);
		mv.addObject("addressId", addressId);
		
		mv.setViewName("popZipcodeList");
		return mv;
	}

}
